#!/usr/bin/python

# This script will accept several ALN files and will run ancescon in parallel, and return a list
# of Ungapped predicted sequences

import subprocess
import re
import tempfile

def predict(aln,name,dest):
	reout = re.compile('Root_MidPoint\s+(A-Z,-)')
	this = tempfile.NamedTemporaryFile(delete=False)
	alignment = open(aln,'r').read()
	this.write(re.sub('CLUSTAL\s+.+\\n','',alignment))
	this.seek(0)
	command = './ancescon.sh %s %s %s' %(this.name,name,dest)
	handle=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE)
	return handle
	#result = handle.communicate()[0]
	#sequence = reout.search(result).groups()[0]
	#sequences.append(sequence.replace('-',''))
	#return result

